package cvi.com.reader.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cvi.com.reader.R;
import cvi.com.reader.bean.CategoriesBean;
import cvi.com.reader.bean.GridViewBean;
import cvi.com.reader.bean.HomePageDataBean;
import cvi.com.reader.bean.constant;

/**
 * Created by 梅涛 on 2020/7/23.
 */

public class HomePageGridAdapter extends BaseAdapter {
    public List<CategoriesBean.RowsBean> getGridViewBeanList() {
        return gridViewBeanList;
    }

    public void setGridViewBeanList(List<CategoriesBean.RowsBean> gridViewBeanList) {
        this.gridViewBeanList = gridViewBeanList;
    }

    private Context context;
    private List<CategoriesBean.RowsBean> gridViewBeanList;

    public HomePageGridAdapter(Context context, List<CategoriesBean.RowsBean> gridViewBeanList) {
        this.context = context;
        this.gridViewBeanList = gridViewBeanList;
    }

    @Override
    public int getCount() {
        return gridViewBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return gridViewBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViHolder viHolder = null;
        CategoriesBean.RowsBean gridViewBean = gridViewBeanList.get(i);
        if (view == null) {
            viHolder = new ViHolder();
            view = LayoutInflater.from(context).inflate(
                    R.layout.item_home_page_gridview, null);
            viHolder.grid_ima = (ImageView) view.findViewById(R.id.grid_ima);
            viHolder.grid_tv = (TextView) view.findViewById(R.id.grid_tv);
            view.setTag(viHolder);
        } else {
            viHolder = (ViHolder) view.getTag();
        }
       // Log.d("fdgdg22",gridViewBean.getName() +"    " +"http://"+constant.URL+gridViewBean.getImage());
        viHolder.grid_tv.setText(gridViewBean.getName());
       Glide.with(context).load(gridViewBean.getIcon()).into(viHolder.grid_ima);
        return view;
    }

    class ViHolder {
        ImageView grid_ima;

        TextView grid_tv;
    }


}
